/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lt.ntec.danblog.server.core.model.objectify;

import com.google.inject.Inject;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.Id;
import lt.ntec.danblog.server.core.model.User;

/**
 *
 * @author Tadas
 */
class ObjectifyUser implements User {
    private Date lastAccessDate;
    private String name;
    private String email;
    private boolean admin;

    private com.google.appengine.api.users.User sysUser;
    
    private List<String> roles = new LinkedList<String>();

    @Id
    private Long id;
    
    public ObjectifyUser(){
        
    }

    @Inject
    public ObjectifyUser(com.google.appengine.api.users.User user) {
        this.sysUser = user;
        this.email = user.getEmail();
        this.name = user.getNickname();
    }

    @Override
    public void setLastAccessDate(Date date) {
        this.lastAccessDate = date;
    }

    @Override
    public Date getLastAccessDate() {
        return lastAccessDate;
    }

    @Override
    public String getName() {
       return name;
    }

    @Override
    public String getEmail() {
       return email;
    }

    @Override
    public boolean isAdmin() {
        return admin;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public List<String> getRoles() {
        return roles;
    }

    @Override
    public void setAdmin(boolean admin) {
        this.admin = admin;
    }

    @Override
    public void addRole(String role) {
        roles.add(role);
    }

    @Override
    public void removeRole(String role) {
        roles.remove(role);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        
        if (!(obj instanceof User)) {
            return false;
        }

        final User other = (User) obj;
        if (this.getId() != other.getId()) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 89 * hash + (this.email != null ? this.email.hashCode() : 0);
        hash = 89 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
    
    

}
